feat: 新增 Provider 抽象系统支持插件提供翻译和 OCR 能力#560
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'Provider' abstraction to ZTools, allowing translation and OCR capabilities to be provided by plugins and managed centrally. It includes a new 'Providers' settings page, a ProviderManager to aggregate built-in and plugin providers, and exposed APIs for other plugins to consume these services. Feedback on the changes suggests correcting a documentation typo regarding translation.image, adding error logging to a silent catch block in the settings UI, and replacing an any type with a concrete type in the TypeScript definitions for better type safety.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| | `translation` | 文本翻译 | `{ text, from?, to? }` | `{ text, detectedFrom? }` | | ||
| | `ocr` | 图片文字识别 | `{ image, lang? }` | `{ text, blocks?, confidence? }` | | ||
|
|
||
| - `translation.image` / `ocr.image` 可为:本地路径 / `data:` URI / `http(s)` URL(具体支持取决于实现)。 |
There was a problem hiding this comment.
| } catch { | ||
| providerTypes.value = [] | ||
| } |
| setParams: ( | ||
| providerId: string, | ||
| params: Record<string, unknown> | ||
| ) => Promise<{ success: boolean; data?: any; error?: string }> |
There was a problem hiding this comment.
为了增强类型安全和代码可读性,建议为 setParams 方法返回的 data 提供一个具体的类型,而不是使用 any。可以参考 getSettings 等方法的返回类型,保持一致性。
| ) => Promise<{ success: boolean; data?: any; error?: string }> | |
| ) => Promise<{ success: boolean; data?: { enabled: Partial<Record<'translation' | 'ocr', string[]>>; defaultId: Partial<Record<'translation' | 'ocr', string>>; params: Record<string, Record<string, unknown>>; }; error?: string }> |
|
部分功能还不够稳定,再等我看看迭代一下 |
将 providers 字段的 key 从「必须等于 type」改为「插件内唯一标识」, value.type 决定类别。运行时 registerProvider / __invokeRegisteredProvider / 注册跟踪全部改为按声明 key 派发,使单插件可对同一 type 声明多条 (如 baidu/google 都为 translation)。 向后兼容:旧插件 key===type 用法保持不变。 - src/shared/providerShared.ts: PluginProvidersField 改为 Record<string, decl>, ProviderEntry 新增 key 字段,buildPluginProviderId 参数语义改为 key - src/main/core/provider/providerManager.ts: sanitize/getAllProviders/ registerProvider/invoke 全部按 key 工作 - resources/preload.js: registerProvider/__invokeRegisteredProvider 按 key 存取 - docs: 更新开发指南与示例 README,补「同一 type 多条」示例 - tests: 新增多声明用例,保留兼容回归
变更概要: